"""队列"""
from .exceptions import DataStructureIsEmpty


class MyQueueIsEmpty(ValueError):
    pass


class MyQueue:
    def __init__(self):
        self._queue = []

    def is_empty(self):
        return self._queue == []

    def get_size(self):
        return len(self._queue)

    def enqueue(self, element):
        self._queue.append(element)

    def dequeue(self):
        if self.is_empty():
            raise MyQueueIsEmpty("MyQueue is empty!")
        return self._queue.pop(0)

    def get_front(self):
        if self.is_empty():
            raise MyQueueIsEmpty("MyQueue is empty!")
        return self._queue[0]


class LinkedListQueue:
    class Node:
        def __init__(self, data):
            self.data = data
            self.next_node = None

    def __init__(self):
        self.head = None
        self.tail = None
        self._size = 0

    def is_empty(self):
        return self._size == 0

    def get_size(self):
        return self._size

    def enqueue(self, element):
        if self.tail is None:
            self.tail = LinkedListQueue.Node(element)
            self.head = self.tail
            self._size += 1
        else:
            self.tail.next_node = LinkedListQueue.Node(element)
            self.tail = self.tail.next_node
            self._size += 1

    def dequeue(self):
        if self.is_empty():
            raise DataStructureIsEmpty("Dequeue failed! LinkedListQueue is empty.")
        del_node = self.head
        self.head = self.head.next_node
        del_node.next_node = None
        if self.head is None:
            self.tail = None
        self._size -= 1
        return del_node.data

    def get_front(self):
        if self.is_empty():
            raise DataStructureIsEmpty("Get failed! LinkedListQueue is empty.")
        return self.tail.data
